<?php

/****************************************************
DESCRIPTION: 	POST OPTIONS
OPTION HANDLE: 	canon_options_post
****************************************************/


	/****************************************************
	REGISTER MENU
	****************************************************/

	add_action('admin_menu', 'register_canon_options_post');

	function register_canon_options_post () {
		global $screen_handle_canon_options_post;	  	//this is the SCREEN handle used to identify the new admin menu page (notice: different than the add_menu_page handle)

		// Use this instad if submenu
		$screen_handle_canon_options_post = add_submenu_page(
			'handle_canon_options',						//the handle of the parent options page. 
			'Pages & Posts Settings',						//the submenu title that will appear in browser title area.
			'Pages & Posts',									//the on screen name of the submenu
			'manage_options',							//privileges check
			'handle_canon_options_post',				//the handle of this submenu
			'display_options_post'				//the callback function to display the actual submenu page content.
		);

	}

	/****************************************************
	INITIALIZE MENU
	****************************************************/

	add_action('admin_init', 'init_canon_options_post');	
	
	function init_canon_options_post () {
		register_setting(
			'group_canon_options_post',					//group name. The group for the fields custom_options_group
			'canon_options_post',						//the options variabel. THIS IS WEHERE YOUR OPTIONS ARE STORED.
			'validate_canon_options_post'				//optional 3rd param. Callback /function to sanitize and validate
		);

		//if this is first runthrough set default values
		if (get_option('canon_options_post') == FALSE) {		//trying to get options 'canon_options_post' which doesn't yet exist results in FALSE
		 	$options = array (

			 		'show_tags'						=> 'checked',
			 		'show_post_nav'					=> 'checked',
			 		'show_comments'					=> 'checked',

		 			'homepage_blog_style'			=> 'full',
		 			'blog_style'					=> 'full',
		 			'cat_style'						=> 'full',
		 			'show_cat_title'				=> 'unchecked',
		 			'show_cat_description'			=> 'unchecked',

			 		'search_box_text'				=> 'What are you looking for?',
			 		'404_title'						=> 'Page not found',
			 		'404_msg'						=> "Sorry, you're lost my friend, the page you're looking for does not exist anymore. Take your luck at searching for a new one.",
		 			'show_tab' 						=> 'basic',

					'use_woocommerce_sidebar'		=> 'unchecked',
					'woocommerce_sidebar'			=> 'canon_woocommerce_widget_area',

				);

			update_option('canon_options_post', $options);
		}
	}



	/****************************************************
	VALIDATE INPUT AND DISPLAY MENU
	****************************************************/

	//remember this will strip all html php tags, strip slashes and convert quotation marks. This is not always what you want (maybe you want a field for HTML?) why you might want to modify this part.	
	function validate_canon_options_post ($new_instance) {				
		return $new_instance;
	}

	//display the menus
	function display_options_post () {
		require "options_post.php";
	}